using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class LevelEditor : MonoBehaviour, IComparer<LevelIndex>
{
	private void Start()
	{
	}

	private void Update()
	{
		if (UnityEngine.Input.GetKeyDown(KeyCode.S))
		{
			Save();
		}
	}

	private void Save()
	{
		using (StreamWriter streamWriter = File.CreateText("text.xml"))
		{
			LevelIndex[] componentsInChildren = base.gameObject.GetComponentsInChildren<LevelIndex>();
			Array.Sort(componentsInChildren, this);
			foreach (LevelIndex levelIndex in componentsInChildren)
			{
				RectTransform component = levelIndex.GetComponent<RectTransform>();
				Vector2 anchoredPosition = component.anchoredPosition;
				float x = anchoredPosition.x;
				Vector2 anchoredPosition2 = component.anchoredPosition;
				float y = anchoredPosition2.y;
				streamWriter.WriteLine("<level>");
				streamWriter.WriteLine($"<id>{levelIndex.id}</id>");
				streamWriter.WriteLine($"<x>{x}</x>");
				streamWriter.WriteLine($"<y>{y}</y>");
				streamWriter.WriteLine("</level>");
			}
		}
		UnityEngine.Debug.Log(" save finish! ");
	}

	public int Compare(LevelIndex x, LevelIndex y)
	{
		return x.id - y.id;
	}
}
